home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / net-tools / aweb+tools / awebftp / awebftp.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1996-06-19  |  15.2 KB  |  362 lines

  1. /* AwebFTP - FTP plug-in for Aweb
  2.  
  3. */ vers="Version 1.3"
  4. /*
  5.     By Josef Faulkner (panther@gate.net) IRC: Josef
  6.  
  7.     Description:
  8.     ¯¯¯¯¯¯¯¯¯¯¯¯
  9.     This plugin will allow you to do inline FTPing of files on the net,
  10.     without the need to call an external FTP program (except FTPMount, which
  11.     is transparent).  It will distinguish between a directory and a file, and
  12.     act accordingly.
  13.  
  14.     Features:
  15.     ¯¯¯¯¯¯¯¯¯
  16.         o Fast reaction, since FTPMount does a lot of cacheing of dirs
  17.         o Asyncronous download (thanks to Aweb), you can continue browsing
  18.           while it downloads, and Aweb will inform you when the transfer
  19.           has completed!
  20.         o Brings up a requestor to ask what you want to save as
  21.     New for 1.1:
  22.         o You can now upload to the directory if you type the name of a file
  23.           in a form at the bottom of the list (or leave blank, and it will
  24.           give you a requester asking for a file)
  25.         o Make directories
  26.         o Delete a file (only one at a time, currently)
  27.     New for 1.2:
  28.         o WBCopy command used to copy files w/ progress meter
  29.           Thanks to Bastian H. Frank for developing this handy program!
  30.     New for 1.3:
  31.         o Much faster:
  32.             o No longer parses list output, uses lformat to create listing
  33.     New for 1.4:
  34.         o AmiFTP is now loadable from the inside!
  35.             o Will detect if amiftp is already loaded, and go to the directory
  36.             o Doesn't disconnect and reconnect if amiftp already has the host open
  37.  
  38.     Requirements:
  39.     ¯¯¯¯¯¯¯¯¯¯¯¯¯
  40.     FTPMount version 8 (or newer) must be installed and running
  41.         available on Aminet:
  42.         FTPMount-1.0.lha  comm/tcp   109K Mounts FTP sites
  43.     WBCopy (aminet/util/cli/WBCopy.lha) must be in your path
  44.         Not only does this program solve the problem with softlinks, but
  45.         it also gives a progress meter (a much requested feature)!
  46.     (optional, but recommended)
  47.     AmiFTP (from http://www.lysator.liu.se/~lilja/AmiFTP.html)
  48.  
  49.     Installation:
  50.     ¯¯¯¯¯¯¯¯¯¯¯¯¯
  51.     1) Put this script in the same directory that the Aweb executable is in.
  52.     2) Set Aweb to the following settings:
  53.       ----------------------------------------------
  54.         Network 3: External Programs
  55.                    ftp:
  56.           Command:  sys:rexxc/rx
  57.         Arguments:  awebftp.rexx %s %s %s  <--- *** NOTE *THREE* %s's ***
  58.       ----------------------------------------------
  59.     3) Put WBCopy in your path (ie C:)
  60.     4) Set your preferences for this script below:
  61.  
  62.     Known Bugs:
  63.     ¯¯¯¯¯¯¯¯¯¯¯
  64.     Linked files are sometimes thought to be directories in AmigaDOS, and
  65.     may wind up returning an empty directory listing instead of the actual
  66.     file.
  67.     I've attempted to correct this by checking if the link clicked on has a
  68.     period in the name, if so, it assumes it's a file instead.
  69.     Hopefully this bug is obsolete with the new copy program.  Let me know if
  70.     you find any URL's that this still happens on.
  71.  
  72.     Many people are getting "out of memory" errors.  This should only be
  73.     occuring on old versions of AwebFTP, and usually only when they forget
  74.     to pass all three %s arguments in aweb's preferences.
  75. */
  76.  
  77. /****AwebFTP Preferences***********************************************/
  78.  
  79. savedir='RAM:'                /* Default directory to download to */
  80. amiftpexe='N:AmiFTP/AmiFTP'   /* Path and name of your amiftp executable */
  81.  
  82. /**********************************************************************/
  83.  
  84. if ~show('L','rexxsupport.library') then if ~addlib('rexxsupport.library',0,-30,0) then exit 20
  85. tmpfile='t:awebftp'time(S)'.html'
  86. address command 'delete t:awebftp#? >NIL:'
  87. parse arg cmds
  88.  
  89. if left(upper(cmds),3)='URL' then do
  90.     do until cmds=''
  91.         parse var cmds name'="'value'"'cmds
  92.         if left(cmds,1)='&' then cmds=right(cmds,length(cmds)-1)
  93.         interpret name'=value'
  94.     end
  95.     select
  96.         when function='upload' then do
  97.             call open(1,tmpfile,w)
  98.             call writeln(1,'<html><head><title>About AwebFTP</title></head><body>')
  99.             if (exists(file))&(file~='FILE') then do
  100.                 address command 'copy 'text' 'url        
  101.                 if rc<20 then call writeln(1,'<h1>Transfer Successful</h1><h2>'text' uploaded.</h2>')
  102.                 else call writeln(1,'<h1>Error</h1><h3>Could not transfer <b>'text'</b> to 'url'</h3>')
  103.             end
  104.             else do
  105.                 address command 'requestfile RAM: >t:awebftp.tmp'
  106.                 call open(2,'t:awebftp.tmp',r)
  107.                 text=readln(2)
  108.                 call close(2)
  109.                 if word(text,1)~='no' then do
  110.                     parse var text .'"'text'"'.
  111.                     if exists(text) then do
  112.                         call putawebmsg('<h3>Now uploading 'text' to 'url'.</h3>You may continue using Aweb asyncronously (especially if file is long).')
  113.                         address command 'copy 'text' 'url
  114.                         if rc<10 then call writeln(1,'<h1>Transfer Successful</h1><h2>'text' uploaded.</h2><a href="'url'">Go Back</a>')
  115.                         else call writeln(1,'<h1>Error</h1><h3>Could not transfer <b>'text'</b> to 'url'</h3>')
  116.                     end
  117.                     else call writeln(1,'<h1>Error</h1><h3>Could not open <b>'text'</b> to send</h3>')
  118.                 end
  119.                 else call writeln(1,'<h1>Transfer Cancelled</h1>')
  120.             end
  121.             call writeln(1,'</body></html>')    
  122.             call close(1)
  123.             address AWEB.1 'OPEN file://localhost/'tmpfile
  124.             exit
  125.         end
  126.         when function='makedir' then do
  127.             if file~='FILE' then do
  128.                 if exists(url||file) then call putawebmsg("Directory already exists!")
  129.                 else do
  130.                     call putawebmsg("Making directory.  Please wait.<h5>(Ignore this if [Back]ing up)</h5>")
  131.                     address command 'makedir 'url||file
  132.                     if rc<10 then call putawebmsg('Directory 'file' created successfully. <br><a href="'url'">Go Back</a>')
  133.                     else call putawebmsg("<h1>Error</h1>Directory was NOT created.")
  134.                 end
  135.             end
  136.             else call putawebmsg("No directory specified.")
  137.             exit
  138.         end
  139.         when function='delete' then do
  140.             if file~='FILE' then do
  141.                 if exists(url||file) then do
  142.                     address command 'requestchoice "Delete File" "Delete 'file' ?" "Delete|Cancel" >t:awebftpchoice.tmp'
  143.                     if open(1,'t:awebftpchoice.tmp',r) then do
  144.                         text=readln(1)
  145.                         if strip(text)='1' then do
  146.                             address command 'delete 'url||file' >t:awebftp.tmp'
  147.                             if rc<10 then call putawebmsg('File <b>'file'</b> deleted. <br><a href="'url'">Go Back</a>')
  148.                             else call putawebmsg("<h1>Error</h1>Error with deletion")                
  149.                         end
  150.                         else call putawebmsg("Delete Cancelled.")
  151.                     end
  152.                 end
  153.                 else call putawebmsg('<h1>Error</h1><b>'file'</b> does not exist!')
  154.             end
  155.             else call putawebmsg("No directory specified.")
  156.             exit
  157.         end
  158.         when function='amiftp' then do
  159.             parse var url 'ftp://'hostname'/'dirs
  160.             dirs='/'dirs
  161.             if showlist(P,'AMIFTP') then do
  162.                 address 'AMIFTP' 'GETATTR STEM ainfo'
  163.                 if (ainfo.HOST ~= hostname) then do
  164.                     address 'AMIFTP' 'DISCONNECT'
  165.                     address 'AMIFTP' 'SETATTR HOST' hostname
  166.                     address 'AMIFTP' 'CONNECT NOSCAN'
  167.                 end
  168.                 address 'AMIFTP' 'CD' dirs
  169.             end
  170.             else do
  171.                 address command amiftpexe
  172.                 timeout=0
  173.                 address command 'waitforport AMIFTP'
  174.                 if (showlist(P,'AMIFTP')) then do
  175.                     address 'AMIFTP' 'GETATTR STEM ainfo'
  176.                     if (ainfo.HOST ~= hostname) then do
  177.                         address 'AMIFTP' 'DISCONNECT'
  178.                         address 'AMIFTP' 'SETATTR HOST' hostname
  179.                         address 'AMIFTP' 'CONNECT NOSCAN'
  180.                     end
  181.                     address 'AMIFTP' 'CD' dirs
  182.                 end
  183.                 else do
  184.                     putawebmsg('Error: Couldn''t run AmiFTP')
  185.                     exit
  186.                 end
  187.             end
  188.         end    
  189.         otherwise do
  190.             call putawebmsg('Program Error: please <a href="mailto:panther@gate.net">mail</a> author w/ errorcode: F-'function' and conditions under which it failed.')
  191.         end
  192.     end
  193.     exit
  194. end
  195.  
  196. parse var cmds server' 'file' 'screen
  197. if screen='' then screen='Aweb'
  198. if server='about' then do
  199.     call open(1,tmpfile,w)
  200.     call writeln(1,'<html><head><title>About AwebFTP</title></head><body>')
  201.     call writeln(1,'<h1>About AwebFTP 'word(vers,2)'</h1>')
  202.     call writeln(1,'AwebFTP is an FTP plug-in arexx script for Aweb, which does FTP inside Aweb''s GUI, provided you have FTPMount installed')
  203.     call writeln(1,'<p><h2>Features of AwebFTP</h2><ul>')
  204.     call writeln(1,'<li>Fast reaction, since FTPMount does caches dirs.')
  205.     call writeln(1,'<li>Inline - Stays within the Aweb GUI.')
  206.     call writeln(1,'<li>Asyncronous download (thanks to Aweb), you can continue browsing while it downloads, and Aweb will inform you when the transfer has completed!')
  207.     call writeln(1,'<li>Brings up a requestor to ask what you want to save as.')
  208.     call writeln(1,'</ul>New for 1.1:<ul>')
  209.     call writeln(1,'<li>You can now upload to the directory if you type the name of a file in a form at the bottom of the list (or leave blank, and it will give you a requester asking for a file)')
  210.     call writeln(1,'<li>Make directories')
  211.     call writeln(1,'<li>Delete a file (currently only one file at a time)')
  212.     call writeln(1,'<li>Title is now a link: click to refresh the list after send/makedir/delete, etc')
  213.     call writeln(1,'</ul>New for 1.2:<ul>')
  214.     call writeln(1,'<li>WBCopy command used to copy files with progress meter')
  215.     call writeln(1,'<br>Thanks to Bastian H. Frank for developing this handy program!')
  216.     call writeln(1,'</ul>New for 1.3:<ul>')
  217.     call writeln(1,'<li>Much faster:<ul>')
  218.     call writeln(1,'<li>No longer parses list output, uses lformat to create listing')
  219.     call writeln(1,'</ul><li>AmiFTP can now be automatically loaded and set to the current dir!<ul>');
  220.     call writeln(1,'<li>Will detect if amiftp is already loaded, and go to the directory');
  221.     call writeln(1,'<li>Doesn''t disconnect and reconnect if amiftp already has the host open');
  222.     call writeln(1,'</ul></ul>')
  223.     call writeln(1,'</ul><p><h2>Known Bugs</h2><ul>')
  224.     call writeln(1,'<li>Linked files are sometimes thought to be directories in AmigaDOS, and may wind up returning an empty directory listing instead of the actual file.')
  225.     call writeln(1,'<p>I''ve attempted to correct this by checking if the link clicked on has a period in the name, if so, it assumes it''s a file instead.  Hopefully this bug is obsolete with the new copy program.  Let me know if you find any URL''s that this still happens on.<p>')
  226.     call writeln(1,'<li>Many people are getting "out of memory" errors.  This should only be    occuring on old versions of AwebFTP, and usually only when they forget    to pass all three %s arguments in aweb''s preferences.  If this is still occuring in this version for you, PLEASE let me know the URL.')
  227.     call writeln(1,'</ul><p><h2>AwebFTP Author</h2>')
  228.     call writeln(1,'<p>AwebFTP is written by <a href="http://www.versanet.com/~josef/">me</a> (<a href="mailto:panther@gate.net">panther@gate.net</a>), Josef on <a href="irc://innernet.org/#Amiga">IRC</a>.  I have also written a few other arexx scripts for Aweb, and over a hundred arexx scripts for Grapevine IRC client (mostly available on my <a href="http://www.versanet.com/~josef/">home page</a>.')
  229.     call writeln(1,'<hr><a href="http://ftp.wustl.edu/aminetbin/find?ftpmount">Latest FTPMount from Aminet</a> | <a href="http://www.versanet.com/~josef/aweb">Other Aweb Scripts</a> | <a href="http://www.versanet.com/~josef/crap/net.html">Other Net Applications</a>')
  230.     call writeln(1,'</body></html>')
  231.     call close(1)
  232.     address AWEB.1 'OPEN file://localhost/'tmpfile
  233.     exit
  234. end
  235. if server='upload' then do
  236. end
  237. do
  238.     if right(server,1)~='/' then server=server'/'
  239.     if length(file)>0 then do
  240.         filebk=file
  241.         dir=''
  242.         do until index(filebk,'/')=0
  243.             parse var filebk dirbk'/'filebk
  244.             dir=dir||dirbk'/'
  245.         end
  246.         file=filebk
  247.         url='ftp://'server||dir||file
  248.     end
  249.     else url='ftp://'server
  250.     call putawebmsg('Opening 'url' -  Please wait. <h5>(Ignore this if [Back]ing up)</h5>')
  251.     if exists(url) then do
  252.         info=statef(url)
  253.         type=word(info,1)
  254.         if type='DIR' then do
  255.             if index(file,'.')>0 then type='FILE'
  256.         end
  257.         size=word(info,2)
  258.         select
  259.             when type='DIR' then do
  260.                 if right(url,1)~='/' then url=url'/'
  261.                 call open(2,tmpfile,w)
  262.                 call writeln(2,'<html><head><title>'url'</title></head><body>')
  263.                 call writeln(2,'<form action="x-aweb:rexx/awebftp.rexx">')
  264.                 call writeln(2,'<input type=hidden name=url value="'url'">')
  265.                 call writeln(2,'<input type=hidden name=function value=amiftp>')
  266.                 if(showlist(P,'AMIFTP')) then do
  267.                     call writeln(2,'<input type=submit value="Update AmiFTP!")></form><pre>')
  268.                 end
  269.                 else do
  270.                     call writeln(2,'<input type=submit value="Load AmiFTP!")></form><pre>')
  271.                 end
  272.                 call writeln(2,'<h2>Directory of <a href="'url'">'url'</a></h2>')
  273.                 call writeln(2,'<hr>Size        Name                       Date<hr>')
  274.                 call close(2)
  275.                 address command 'list 'url' lformat "%10d %10l <a href='url'%n>%s</a>" >>'tmpfile
  276.                 call open(2,tmpfile,a)
  277.                 call writeln(2,'</pre><hr>')
  278.                 call writeln(2,'<form action="x-aweb:rexx/awebftp.rexx">')
  279.                 call writeln(2,'<input type=hidden name=url value="'url'">')
  280.                 call writeln(2,'<input type=hidden name=function value=upload>')
  281.                 call writeln(2,'<input size=60 maxlength=120 name=file>')
  282.                 call writeln(2,'<input type=submit value="Send File")></form>')
  283.                 call writeln(2,'<form action="x-aweb:rexx/awebftp.rexx">')
  284.                 call writeln(2,'<input type=hidden name=url value="'url'">')
  285.                 call writeln(2,'<input type=hidden name=function value=makedir>')
  286.                 call writeln(2,'<input size=60 maxlength=120 name=file>')
  287.                 call writeln(2,'<input type=submit value="Make Dir")></form>')
  288.                 call writeln(2,'<form action="x-aweb:rexx/awebftp.rexx">')
  289.                 call writeln(2,'<input type=hidden name=url value="'url'">')
  290.                 call writeln(2,'<input type=hidden name=function value=delete>')
  291.                 call writeln(2,'<input size=60 maxlength=120 name=file>')
  292.                 call writeln(2,'<input type=submit value="Delete File")></form>')
  293.                 call writeln(2,'<hr><a href="ftp://about/">AwebFTP</a> 'vers' by <a href="mailto:panther@gate.net">Josef Faulkner</a>.')
  294.                 call writeln(2,'</body></html>')
  295.                 call close(1)
  296.                 call close(2)
  297.                 address AWEB.1 'open file://localhost/'tmpfile
  298.             end
  299.             when type='FILE' then do
  300.                 if open(11,url,r) then do
  301.                     call close(11)
  302.                     address command 'requestchoice "AWebFTP" "View or Save 'file'?" "View|Save|Cancel" pubscreen="'screen'" >t:awebftpchoice.tmp'
  303.                     call open(1,'t:awebftpchoice.tmp',r)
  304.                     text=readln(1)
  305.                     call close(1)
  306.                     select
  307.                         when text=0 then do
  308.                             call putawebmsg('Transfer aborted.')
  309.                         end
  310.                         when text=1 then do
  311.                             call putawebmsg('Downloading 'url' to view in Aweb.')
  312.                             address command 'wbcopy 'url' 'tmpfile' >nil:'
  313.                             address AWEB.1 'open file://localhost/'tmpfile
  314.                         end
  315.                         when text=2 then do
  316.                             address command 'requestfile drawer='savedir' file='file' pubscreen='screen' >'tmpfile
  317.                             call open(1,tmpfile,r)
  318.                             text=readln(1)
  319.                             call close(1)
  320.                             if left(text,7)~='no more' then do
  321.                                 call putawebmsg('Downloading 'file' ('size' bytes).<br> You may resume using Aweb, and a message will appear when transfer is complete.')
  322.                                 address command 'wbcopy 'url' 'text' >nil:'
  323.                                 call putawebmsg('Download of 'file' to 'text' complete.')
  324.                             end
  325.                             else do
  326.                                 call putawebmsg('Transfer aborted.')
  327.                             end
  328.                         end
  329.                         otherwise do
  330.                             call putawebmsg('Strange Arexx bug.  Inform <a href="mailto:panther@gate.net">author</a> of AwebFTP bug #2-'text)
  331.                             exit
  332.                         end
  333.                     end
  334.                 end
  335.                 else do
  336.                     call putawebmsg('Sorry, could not open 'url' for read access.')
  337.                 end
  338.             end
  339.             otherwise do
  340.                 call putawebmsg('Strange Arexx bug.  Inform <a href="mailto:panther@gate.net">author</a> of AwebFTP bug #1-'type)
  341.                 exit
  342.             end
  343.         end
  344.     end
  345.     else do
  346.         call putawebmsg('Sorry, 'url' doesn''t exist.')
  347.     end
  348. end
  349. exit
  350.  
  351. PUTAWEBMSG: procedure
  352. parse arg text
  353.     address command 'delete t:awebmsg#?.html >NIL:'
  354.     fname='t:awebmsg'time(S)'.html'
  355.     call open(4,fname,w)
  356.     call writeln(4,'<html><head><title>AwebFTP Message</title></head><body>')
  357.     call writeln(4,'<h3>'text'</h3>')
  358.     call writeln(4,'</body>')
  359.     call close(4)
  360.     address AWEB.1 'OPEN file://localhost/'fname
  361. return
  362.